package wh.ispct.util

/**
 * 树节点
 * 
 * @author zhou
 *
 */
class ExtTreeNode extends HashMap {
	static final String ID_KEY = "id";
	static final String TEXT_KEY = "text";
	static final String PARENT_ID_KEY = "parentId";
	static final String TYPE_KEY = "type";
	static final String LEAF_KEY = "leaf";
	static final String CHILDREN_KEY = "children";
	

	/**
	 * 构造函数
	 *
	 */
	public ExtTreeNode(String id,String parentId, String text, String type,boolean leaf) {
		super();
		this.put(ID_KEY, id);
		this.put(PARENT_ID_KEY, parentId);
		this.put(TEXT_KEY, text);
		this.put(TYPE_KEY, type);
		this.put(LEAF_KEY, leaf);
	}
	
	/**
	 * 得到Id
	 *
	 * @return
	 */
	public String getId(){
		return (String)this.get(ID_KEY);
	}
	
	/**
	 * 得到ParentId
	 *
	 * @return
	 */
	public String getParentId(){
		return (String)this.get(PARENT_ID_KEY);
	}

	/**
	 * 子节点
	 *
	 * @param children
	 */
	public void setChildren(List<ExtTreeNode> children) {
		this.put(CHILDREN_KEY, children);
	}
	
	/**
	 * 添加子节点
	 *
	 * @param child
	 */
	public void addChild(ExtTreeNode child){
		if(this.containsKey(CHILDREN_KEY) == false){
			this.setChildren(new ArrayList<ExtTreeNode>());
		}
		((List)this.get(CHILDREN_KEY)).add(child);
		this.put(LEAF_KEY, false);
	}
}
